import BuffUtil from '@/BuffUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 大地之盾
 **/
export default class SM_EarthShield extends AbilityBase {
    static instance: SM_EarthShield;
    buffType: AppBuffType = {
        id: 'buff_SM_EarthShield',
        art: this.art,
        name: this.abilityName,
        ubertip: '',
        dur: 20,
        stackCountMax: -1,
        attribute: {
            护甲百分比: 0.15,
            魔抗百分比: 0.15,
        },
        targetArt: 'Stone Shield\\Stone Shield.mdx',
        targetAttach: 'origin',
    };
    constructor(id: string = 'Addd') {
        super(id);
        SM_EarthShield.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
        EventManager.onTakeDamage(this.onDamage.bind(this));
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        // let buff = BuffUtil.addBuff(target, this.buffType.id, source);
        // buff.stackCount = 3 + R2I(this.getAbilityLevel(source) / 2);
        BuffCommon.addBuff({
            target,
            caster: source,
            buffTypeId: this.buffType.id,
            ablityId: this.id,
            config: { stack: 3 + R2I(this.getAbilityLevel(source) / 2) },
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    onDamage(d: DamageEventData) {
        let buff = BuffUtil.getUnitBuff(d.target, this.buffType.id);
        if (!buff) return;
        buff.stackCount -= 1;
        if (buff.stackCount <= 0) buff.destroy();
        let lv = this.getAbilityLevel(buff.getCaster());
        let dmg = 30 * lv + UnitCommon.取法强(buff.getCaster()) * (0.8 + 0.4 * lv);
        DamageSystemInstance.applyHeal(d.target, buff.getCaster(), dmg, this.id);
    }
}
